/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package EmpMonthlySal;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author Mukesh
 */
public class AddMonthlySal extends HttpServlet {

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        HttpSession session = request.getSession();
        try {
            MonthlySalBean msb = new MonthlySalBean();

            msb.setYear(request.getParameter("year"));

            msb.setMonth(request.getParameter("month"));
            if (request.getParameter("wdays").length() != 0) {
                msb.setWorkingDays(Integer.parseInt(request.getParameter("wdays")));
            }
            if (request.getParameter("total").length() != 0) {
                msb.setAmount(Integer.parseInt(request.getParameter("total")));
            }
            if (request.getParameter("pmode").length() != 0) {
                msb.setPayMode(Integer.parseInt(request.getParameter("pmode")));
            }

            msb.setChequeNo(request.getParameter("cheque"));

            if (request.getParameter("empid").length() != 0) {
                msb.setEmpId(Long.parseLong(request.getParameter("empid")));
            }
            msb.setBank(request.getParameter("bank"));
            msb.setBranch(request.getParameter("branch"));
            int i = Query.add(msb);
            if (i != 0) {
                session.setAttribute("msg", "Salary Updated Successfully.");
                session.setAttribute("status", "success");
                response.sendRedirect("/RIT/Services/Payroll/CalcSalSearch.jsp");
            } else {
                session.setAttribute("msg", "Salary Not Done.");
                session.setAttribute("status", "Fail");
                response.sendRedirect("/RIT/Services/Payroll/CalcSalSearch.jsp");
            }
        } catch (Exception e) {
            session.setAttribute("msg", "Salary Not Done.(e)"+e);
            session.setAttribute("status", "Fail");
            response.sendRedirect("/RIT/Services/Payroll/CalcSalSearch.jsp");
        } finally {
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
